<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules">
      <el-form-item label="头像" prop="avatar" style="height:200px">
        <upload v-model="form.avatar"></upload>
      </el-form-item>
      <el-form-item label="姓名" prop="userName">
        <el-input v-model="form.userName"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit('form')">确 定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import upload from "../directive/upload";
export default {
  components: {
    upload
  },
  data() {
    return {
      form: {
        avatar: "",
        userName: ""
      },
      rules: {
        avatar: [{ required: true, message: "请输入头像", trigger: "blur" }],
        userName: [{ required: true, message: "请填写姓名", trigger: "blur" }]
      }
    };
  },
  methods: {
    onSubmit() {
      // alert(formName)
      // console.log(this.$refs[formName]);
      this.$refs.form.validate(valid => {
        if (valid) {
          // 将 this.form 传给后端
          alert("submit!");
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped></style>
